import Auth from '@/util/auth'
import { Promise } from 'core-js';
const state = {
    token: '',
    name: '',
    permissionList: []
}

const mutations = {
    setToken: (state, data) => {
        if(data){
            Auth.setToken(data)
            Auth.setLoginStatus()
        } else {
            Auth.removeToken()
            Auth.removeLoginStatus()
        }
        state.token = data
    },
    setName: (state, data) => {
        state.name = data
    }
}

const actions = {
    // 登出
    logout({commit}) {
        return new Promise((resolve) => {
            commit('setToken', '')
            commit('setName', '', { root: true })
            commit('permissionList', [], {root: true})
            resolve()
        })
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}